﻿using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using XCI.Core;
using XCI.Extensions;

namespace XCI.Sys.Controls
{
    [System.ComponentModel.DesignerCategory("Code")]
    [ToolboxItem(true)]
    public partial class XtraReportx : DevExpress.XtraReports.UI.XtraReport
    {
        private ReportObject _robject;

        public XtraReportx()
        {
            InitializeComponent();
        }

        public void SetReportObject(ReportObject robject)
        {
            _robject = robject;
        }

        private void XtraReport1_ParametersRequestSubmit(object sender, DevExpress.XtraReports.Parameters.ParametersRequestEventArgs e)
        {
            if (_robject == null) return;
            if (_robject.SysReport.Url.IsEmpty()) return;

            var map = new Map();
            foreach (var item in e.ParametersInformation)
            {
                map.Add(item.Parameter.Name, item.Parameter.Value.ToStringOrEmpty());
            }
            this.DataSource = _robject.LoadDataSource(map);
        }
    }
}
